package breeze.framework.reflect;

import breeze.framework.log.SimpleLog;

public interface Retry {

	static <T> T retrys(int count,Retry retry) {
		for (int i = 0; i < count; i++) {
			try {
				return retry.retry();
			} catch (Exception e) {
				SimpleLog.debug(e.getLocalizedMessage());
			}
		}
		return null;
	}
	
	static String retrys(int count,Retry retry,String expect_not) {
		for (int i = 0; i < count; i++) {
			try {
				String result = retry.retry();
				if(null == expect_not) {
					if(null != result) {
						return result;
					}
				}else if(!expect_not.equals(result)){
					return result;
				}
			} catch (Exception e) {
				SimpleLog.debug(e.getLocalizedMessage());
			}
		}
		return null;
	}
	
	public <T> T retry() throws Exception;
	
	public static void main(String[] args) {
		Retry.retrys(3,new Retry() {
			public <T> T retry() throws Exception {
				System.out.println("测试");
				throw new Exception("测试");
			}
		});
	}
}
